public class Demo12 {
//	private static Object  locker1=new Object();
//	private static Object  locker2=new Object();
	public static void main1(String[] args)  {
		Thread t1=new Thread(()->{
			synchronized (locker1) {
				try {
					locker1.wait();
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
			}
			synchronized (locker2) {
				System.out.println("111111111111");
			}
			System.out.println("aaaaaaaaaaaaa");
		});
		t1.start();
	}


	private static Object  locker1=new Object();
	private static Object  locker2=new Object();
	private static Object  locker3=new Object();

	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(() -> {
			try {
				for (int i = 0; i < 10; i++) {
					synchronized (locker1) {
						locker1.wait();
					}
					System.out.println("A");
					synchronized (locker3) {
						locker3.notify();
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

		Thread t2 = new Thread(() -> {
			try {
				for (int i = 0; i < 10; i++) {
					synchronized (locker2) {
						locker2.wait();
						//当线程二进入到阻塞状态的时候，这时候已经释放锁了，这时候线程1会得到locker2，并将线程1唤醒
						//只有将他唤醒之后，才会重新得到锁
					}
					System.out.print("B");
					synchronized (locker1) {
						locker1.notify();
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

		Thread t3 = new Thread(() -> {
			try {
				for (int i = 0; i < 10; i++) {
					synchronized (locker3) {
						locker3.wait();
					}
					System.out.print("C");
					synchronized (locker2) {
						locker2.notify();
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		t3.start();
		t2.start();
		t1.start();

		Thread.sleep(100);

		// 从线程 t1 启动
		synchronized (locker3) {
			locker3.notify();
		}
	}
}


